﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace trunk.Models
{
    /// <summary>
    /// 在prism等mvvm框架中有实现这个类
    /// </summary>
    public class ObservableObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;

        public virtual bool SetProperty<T>(ref T item, T value,[CallerMemberName]string? propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(item, value))
            {
                return false;
            }
            return true;
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
